import gradio as gr
from ultralytics import YOLO

base_conf, base_iou = 0.25, 0.45
model = YOLO(f'c:/tmp/yolo_v10s.pt')

def detect(image, conf, iou):
    if image is None or type(image) == 'NoneType':
        return None

    results = model(source=image,conf=conf,iou=iou)
    print(results)
    return results[0].plot()

"""
inputs 使用图片路径作为fn的输入
"""
demo = gr.Interface(
    inputs=[gr.Image(type='filepath'),gr.Slider(minimum=0, maximum=1, value=base_conf,label='target confidence show threshold'),gr.Slider(minimum=0, maximum=1, value=base_iou,label='NMS IOU show threshold')],
    outputs=[gr.Image(type='filepath')],
    fn=detect,
)

demo.launch()
